package chabernac.android.wordbattle.paint.crosstile;

import chabernac.android.wordbattle.model.Letter;
import chabernac.android.wordbattle.model.Word;

public class CrossTileDrawableFactory{

  public CrossTileDrawableFactory() {
    super();
  }

  public AbstractCrossTileDrawable createCrossTile(
      Word aSelectedWord, 
      Letter aLetterUpLeft, 
      Letter aLetterUpRight,
      Letter aLetterDownLeft, 
      Letter aLetterDownRight) 
  {
    AbstractCrossTileDrawable aResultCrossTile = null;
    // Check for full cross tile
    if (aLetterUpLeft != null && aLetterUpRight != null && aLetterDownLeft != null && aLetterDownRight != null)
    {
      aResultCrossTile = new FullCrossTileDrawable(aSelectedWord, aLetterUpLeft, aLetterUpRight, aLetterDownLeft, aLetterDownRight);
    }
    // Check for half cross tiles
    else if (aLetterUpLeft != null && aLetterUpRight != null && aLetterDownLeft == null && aLetterDownRight == null)
    {
      aResultCrossTile = new HalfUpCrossTileDrawable(aSelectedWord, aLetterUpLeft, aLetterUpRight);
    }
    else if (aLetterUpLeft == null && aLetterUpRight == null && aLetterDownLeft != null && aLetterDownRight != null)
    {
      aResultCrossTile = new HalfDownCrossTileDrawable(aSelectedWord, aLetterDownLeft, aLetterDownRight);
    }
    else if (aLetterUpLeft != null && aLetterUpRight == null && aLetterDownLeft != null && aLetterDownRight == null)
    {
      aResultCrossTile = new HalfLeftCrossTileDrawable(aSelectedWord, aLetterUpLeft, aLetterDownLeft);
    }
    else if (aLetterUpLeft == null && aLetterUpRight != null && aLetterDownLeft == null && aLetterDownRight != null)
    {
      aResultCrossTile = new HalfRightCrossTileDrawable(aSelectedWord, aLetterUpRight, aLetterDownRight);
    }
    // Check for quarter tiles
    else if (aLetterUpLeft != null && aLetterUpRight == null && aLetterDownLeft == null && aLetterDownRight == null)
    {
      aResultCrossTile = new QuarterUpLeftCrossTileDrawable(aSelectedWord, aLetterUpLeft);
    }
    else if (aLetterUpLeft == null && aLetterUpRight != null && aLetterDownLeft == null && aLetterDownRight == null)
    {
      aResultCrossTile = new QuarterUpRightCrossTileDrawable(aSelectedWord, aLetterUpLeft);
    }
    else if (aLetterUpLeft == null && aLetterUpRight == null && aLetterDownLeft != null && aLetterDownRight == null)
    {
      aResultCrossTile = new QuarterDownLeftCrossTileDrawable(aSelectedWord, aLetterUpLeft);
    }
    else if (aLetterUpLeft == null && aLetterUpRight == null && aLetterDownLeft == null && aLetterDownRight != null)
    {
      aResultCrossTile = new QuarterDownRightCrossTileDrawable(aSelectedWord, aLetterUpLeft);
    }
    // none possible tiles
    else
    {
      throw new UnsupportedOperationException("Cannot create the given tyle: combination of letters is not supported");
    }
    return aResultCrossTile;
  }
}
